********Table 2 - Mexico********

*Load data and create differences
cd "$reploc/data/created_data"
use mex_full, clear

sort pid_link mxfls
drop if mxfls==.
keep if panel==1

*Normalize monetary variables
gen assets_ia_use=assets_ia/1000
gen income_ia_use=income_ia/1000
gen savingnettotal_ia_use=savingnettotal_ia/1000

keep rbuc* mxfls pid_link inflation imp_age panel birthyr grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? married hhsize hhsize_sq Eddum* feelsafehome fear_assaultday fear_assaultnight hhviol times_assaulted disaster assets_ia_use income_ia_use savingnettotal_ia_use homiciderate birthstate yearprov

reshape wide rbuc*  inflation imp_age panel grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co? grbrprovSD_lam0co? married hhsize hhsize_sq Eddum* feelsafehome fear_assaultday fear_assaultnight hhviol times_assaulted disaster assets_ia_use income_ia_use savingnettotal_ia_use homiciderate, i(pid_link) j(mxfls)


local varlist1 rbuc rbuc_nga inflation grbrprovAvg_lam0 grbrprovSD_lam0 grbrprovAvg_lam0co2 grbrprovSD_lam0co2 grbrprovAvg_lam0co3 grbrprovSD_lam0co3 married hhsize hhsize_sq feelsafehome fear_assaultday fear_assaultnight hhviol times_assaulted disaster assets_ia_use income_ia_use savingnettotal_ia_use homiciderate


foreach var in `varlist1'  {
gen `var'dif=.
replace `var'dif=`var'3-`var'2
}

foreach var of varlist Eddum*3 {

local im=substr("`var'",1,length("`var'")-1)

gen `im'dif=.
replace `im'dif=`var'-`im'2

}

*Generate cohort by birthyear variables to cluster on
gen coh_prov_clust=yearprov


*Regressions
local x rbuc_nga
local rhsvari oldmexonly
local rhsvaruse _lam0co3dif
local usei grbr
local macrouse `usei'provAvg`rhsvaruse' `usei'provSD`rhsvaruse'

cd "$reploc/results"

*Column 1
reg `x'dif `macrouse'  inflationdif, vce(cluster coh_prov_clust)
outreg2 using Table2_Mexico.tex, replace label  keep(`macrouse') addtext(\Delta Demographics, o, \Delta Income, o, \Delta Assets, o, \Delta Savings, o, \Delta Violence, o, \Delta Natural Disasters, o) stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 2
reg `x'dif `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif, vce(cluster coh_prov_clust)
outreg2 using Table2_Mexico.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, o, \Delta Assets, o, \Delta Savings, o, \Delta Violence, o, \Delta Natural Disasters, o)stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)
	
*Column 3					
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif, vce(cluster coh_prov_clust)
outreg2 using Table2_Mexico.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, o, \Delta Savings, o, \Delta Violence, o, \Delta Natural Disasters, o)stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)
					
*Column 4			
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif, vce(cluster coh_prov_clust)
outreg2 using Table2_Mexico.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, o, \Delta Violence, o, \Delta Natural Disasters, o)stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 5
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif, vce(cluster coh_prov_clust)
outreg2 using Table2_Mexico.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, o, \Delta Natural Disasters, o)stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)
			
*Column 6			
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif feelsafehomedif fear_assaultdaydif fear_assaultnightdif hhvioldif times_assaulteddif homicideratedif, vce(cluster coh_prov_clust)
outreg2 using Table2_Mexico.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, o)stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)

*Column 7			
reg `x'dif  `macrouse'  inflationdif marrieddif hhsizedif hhsize_sqdif Eddum*dif income_ia_usedif assets_ia_usedif savingnettotal_ia_usedif feelsafehomedif fear_assaultdaydif fear_assaultnightdif hhvioldif times_assaulteddif homicideratedif disasterdif, vce(cluster coh_prov_clust)
outreg2 using Table2_Mexico.tex, append label  keep(`macrouse') addtext(\Delta Demographics, X, \Delta Income, X, \Delta Assets, X, \Delta Savings, X, \Delta Violence, X, \Delta Natural Disasters, X)stats(coef se)  sortvar(`macrouse') dec(2) sdec(2)
			
			
			
